/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fwdisp.content;

import ch.ubique.inieditor.IniEditor;
import fwdisp.MainFrame;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
/**
 *
 * @author rbs
 */
public class Label extends javax.swing.JLabel{

    MainFrame m;
    public Label(MainFrame main)
    {
        super();
        m = main;
    }


    public Label(String text, MainFrame main)
    {
        super(text);
        m = main;
    }

    public void setBorder(Color color, int strength)
    {
        setBorder(BorderFactory.createLineBorder(color, strength));
    }

    public void setStandardFont()
    {
        setFont(new Font("serif", Font.BOLD, 90));
    }

    public void setAlignment(int align)
    {
        setHorizontalAlignment(align);
    }

    public void readSettings(String file, String labelName)
    {
        int labelheight;
        Color fg_color;
        Color bg_color;
        int txtsize;
        boolean bold;

        IniEditor imp = new IniEditor(file);
        try {
            imp.load(file);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "Fehler beim Lesen der Datei. Bitte die settings.ini neu herunterladen.");
            System.exit(-2);
        }

        labelheight = Integer.decode(imp.get(labelName, "labelHeigt"));
        fg_color = Color.decode(imp.get(labelName, "FgColor"));
        bg_color = Color.decode(imp.get(labelName, "BgColor"));
        txtsize = Integer.decode(imp.get(labelName, "TxtSize"));
        bold = Boolean.valueOf(imp.get(labelName, "bold"));

        setSize(m.getWidth(), labelheight);
        setBackground(bg_color);
        setForeground(fg_color);
        if (bold)
            setFont(new Font("serif", Font.BOLD, txtsize));
        else
            setFont(new Font("serif", Font.PLAIN, txtsize));
    }

    public void SetLabelIcon(String pic)
    {
        ImageIcon im = new ImageIcon(pic);
        Image tmp = im.getImage();
        double verhältnis = (double)im.getIconWidth() / im.getIconHeight();
        int perc = (int) (getHeight() * 0.7);
        im = new ImageIcon(tmp.getScaledInstance((int) (perc * verhältnis), perc, Image.SCALE_SMOOTH));
        setIcon(im);
        setIconTextGap(30);
    }


};
